package com.github_dididipapa.common.exception;

import com.github_dididipapa.common.utils.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.NoHandlerFoundException;



/**
 * @description: 远程调用异常处理
 * @author: dididi_papa
 * @email: mitis1624087624@gmail.com
 * @date: 2025/06/22  16:03
 */
@RestControllerAdvice
public class OpenFeignExceptionHandler {

    private final Logger logger = LoggerFactory.getLogger(getClass());
    /**
     * 拦截业务异常
     */
    @ExceptionHandler(OpenFeignException.class)
    public R handleOpenFeignException(OpenFeignException e) {
        R r = new R();
        r.put("code", e.getCode());
        r.put("msg", e.getMessage());

        return r;
    }

    @ExceptionHandler(NoHandlerFoundException.class)
    public R handlerNoFoundException(Exception e) {
        logger.error(e.getMessage(), e);
        return R.error(404, "路径不存在，请检查路径是否正确");
    }

    @ExceptionHandler(Exception.class)
    public R handleException(Exception e) {
        return R.error(500, "服务器异常");
    }
}
